package cc.mllt.demoaopmybatisauth.demos.web.service;

import cc.mllt.demoaopmybatisauth.demos.web.annotation.PermissionRequired;
import cc.mllt.demoaopmybatisauth.demos.web.mapper.UserMapper;
import cc.mllt.demoaopmybatisauth.demos.web.model.entity.User;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MockService {

    @Autowired
    private  UserService userService;
    @Autowired
    private UserMapper userMapper;
    @PermissionRequired(module = "User", operation = "query")
    @PermissionRequired(module = "User", operation = "update")
    public List<Map<String, Object>> getUserInfo() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        // 只选择需要的字段，并使用聚合函数处理非分组字段
        queryWrapper.select("create_by", "COUNT(id) AS user_count")
                .groupBy("create_by");

        // 执行查询并返回 Map 类型的结果
        return userMapper.selectMaps(queryWrapper);
    }
    @PermissionRequired(module = "User", operation = "update")
    public List<User> updateUserInfo() {
        return userService.list();
    }

    @PermissionRequired(module = "User", operation = "delete")
    public List<User> deleteUserInfo() {
        return userService.list();
    }
}
